package com.fh.Thread_Exit;

//需求：启动一个线程t，需要在main线程中停止线程t
public class Exit {
    public static void main(String[] args) {
        A1 a1 = new A1();
        a1.start();
        for (int i = 0;i < 60;i++) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("main线程运行中"+i);
            if (i==30){
                a1.setLoop(false);
            }
        }
    }
}
class A1 extends Thread {
    boolean loop = true ;
    @Override
    public void run() {
        while(loop) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("A1运行中...");
        }
    }
    public void setLoop(boolean loop) {
        this.loop = loop;
    }
}

